$(function() {
    $('.layui-plus').click(function() {
        layer_iframe('添加服务', 'edit');
    });
    window.page = 1;
    window.limit = 10;
    window.options = {
        id: 'data_table',
        elem: '.layui-table.data-table',
        url: location.pathname + location.search,
        where: {},
        page: {
            curr: 1
        },
        limits: [10, 25, 50, 100],
        done: function(res, curr, first) {
            if (!res.data && curr > 1) {
                window.options.page.curr = curr - 1;
                window.tableIns.reload(window.options);
            }
            window.options.page.curr = curr;
            window.page = curr;
            window.limit = res.limit;
        },
        cols: [
            [{
                field: 'title',
                title: '标题',
                unresize: true,
                align: 'center',
                width:'400'
            }, {
                field: 'type',
                title: '服务类型',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.type){
                        case 1: return '<span style="color:#6590DC">有偿</span>';break;
                        case 2: return '<span style="color:#B60000">无偿</span>';break;
                    }
                },
                width:'100'
            }, {
                field: 'pay_price',
                title: '订金',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                field: 'price',
                title: '价格',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                title: '发布人编号',
                unresize: true,
                align: 'center',
                 templet:function(d){
                    return '<div style="cursor:pointer;text-decoration:underline;color:#6590DC" lay-event="user" >'+d.number+'</div>';
                },
                width:'100'
            } , {
                field: 'service_type',
                title: '服务方式 ',
                unresize: true,
                align: 'center',
                templet:function(d){
                    switch(d.type){
                        case 1: return '线上';break;
                        case 2: return '线下';break;
                    }
                },
                width:'100'
            }, {
                field: 'service_time',
                title: '服务时间',
                unresize: true,
                align: 'center',
                width:'120'
            }, {
                field: 'pay_type',
                title: '收费方式',
                unresize: true,
                align: 'center',
                width:'120'
            }, {
                field: 'tel',
                title: '联系电话',
                unresize: true,
                align: 'center',
                width:'120'
            }, {
                field: 'complain',
                title: '投诉次数',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                field: 'add_time',
                title: '发布时间',
                unresize: true,
                align: 'center',
                width:'150'
            }, {
                field: 'complain',
                title: '投诉（次）',
                unresize: true,
                align: 'center',
                width:'100'
            }, {
                title: '操作',
                unresize: true,
                align: 'center',
                toolbar: '#toolbar_normal',
                width:'300'
            }]
        ],
    };
    window.tableIns = laytable.render(window.options);
    laytable.on('tool(data_table)', function(obj) {
        if (obj.event === 'edit') {
            layer_iframe('查看详情', 'edit?id=' + obj.data.id);
        } else if (obj.event === 'del') {
            _ajax_update('确定删除该服务吗?', 'bz_service', obj.data.id, {
                status: 0
            });
        }else if (obj.event === 'user') {
            layer_iframe('会员信息', '/before/user/index?id=' + obj.data.user_id);

        }else if (obj.event === 'buy') {
            layer_iframe('购买记录', '/before/service_buy/index?foreign_key=' + obj.data.user_id);

        }
    });
});
